package com.eboss2.sbs.activity;

import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.eboss2.sbs.R;
import com.eboss2.sbs.activity.base.BaseActivity;
import com.eboss2.sbs.adapter.ImageAdapter;
import com.eboss2.sbs.adapter.OrderListAdapter;
import com.eboss2.sbs.config.Config;
import com.eboss2.sbs.enums.EnumConsts;
import com.eboss2.sbs.http.HttpUtil;
import com.eboss2.sbs.interfaces.EditPriceCallbackListener;
import com.eboss2.sbs.interfaces.EmsCallbackListener;
import com.eboss2.sbs.interfaces.RefundCallbackListener;
import com.eboss2.sbs.model.MessageEvent;
import com.eboss2.sbs.model.OrderListInfo;
import com.eboss2.sbs.model.OrderManagerInfo;
import com.eboss2.sbs.weight.DialogUtils;
import com.eboss2.sbs.weight.MyCustomDialog;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.loopj.android.http.RequestParams;
import com.mytools.tool.activityManager.MyActivityManager;
import com.mytools.tool.views.MyDialog;
import com.tool.utils.utils.StringUtils;
import com.tool.utils.utils.ToastUtils;
import com.tool.utils.view.MyGridView;
import com.tool.utils.view.MyListView;
import com.tool.utils.view.RTextView;
import com.uuzuche.lib_zxing.activity.CaptureActivity;
import com.uuzuche.lib_zxing.activity.CodeUtils;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ActivityOrderDetail extends BaseActivity implements View.OnClickListener {


	private TextView tv_status_name;
	private TextView tv_status_time;
	private LinearLayout ll_address;
	private TextView tv_recipients;
	private TextView tv_address_content;
	private TextView tv_ems_name;
	private TextView tv_ems_no;
	private TextView tv_ems_content;
	private TextView tv_ems_time;
	private TextView tv_pj_content;
	private TextView tv_pj_time;
	private RTextView tv_phone;
	private LinearLayout ll_button;
	private LinearLayout ll_button2;

	private LinearLayout ll_back_content;
	private LinearLayout ll_ems;
	private LinearLayout ll_pj;
	private LinearLayout ll_pay_time;
	private LinearLayout ll_send_time;
	private LinearLayout ll_received_time;
	private LinearLayout ll_refund;

	private TextView tv_btn_1;
	private TextView tv_btn_2;
	private TextView tv_btn_3;
	private TextView tv_btn_4;
	private TextView tv_btn_5;
	private TextView tv_btn_6;
	private RTextView tv_user_name;
	private TextView tv_total_amt;
	private TextView tv_point_amt;
	private TextView tv_coupon_amt;
	private TextView tv_order_count;
	private TextView tv_order_amt;
	private TextView tv_back_content;
	private TextView tv_order_no;
	private TextView tv_order_time;
	private TextView tv_pay_time;
	private TextView tv_send_time;
	private TextView tv_received_time;
	private TextView tv_refund_type;
	private TextView tv_refund_reason;

	private ImageView imgQ1;
	private ImageView img;
	private MyGridView id_gridview1;
	private List<String> imgPath = new ArrayList<>();
	private ImageAdapter imageAdapter;

	private MyListView listview_spec;
	private OrderListAdapter orderListAdapter;

	private List<OrderListInfo> orderListInfos = new ArrayList<>();

	private OrderManagerInfo orderItemDetailInfo;

	private long orderId;

	private EditText emsNo;
	private String type;

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mContext = this;
		setContentView(R.layout.activity_order_manager_all_detail);
		MyActivityManager.getInstance().addActivity(this);
		initView();
	}
	
	private void initView(){
		RelativeLayout relativeLayout = findViewById(R.id.lv_heard);
		relativeLayout.setBackgroundColor(getResources().getColor(R.color.statusBar));
		showView(R.id.titleback_btn_back, true);
		setTvText(R.id.tv_title, "订单详情 ");
		showView(R.id.next_sure, false);
		findViewById(R.id.titleback_btn_back).setOnClickListener(this);

		tv_status_name = textView(R.id.tv_status_name);
		tv_status_time = textView(R.id.tv_status_time);
		tv_recipients = textView(R.id.tv_recipients);
		tv_address_content = textView(R.id.tv_address_content);
		tv_phone = (RTextView) textView(R.id.tv_phone);
		tv_phone.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				if (orderItemDetailInfo == null){
					return;
				}
				final String phone = orderItemDetailInfo.getPhone();
				DialogUtils.alert("拨打 " + phone, null, mContext, new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));
						// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
						startActivity(intent);
					}
				}, new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();

					}
				});
			}
		});
		tv_btn_1 = textView(R.id.tv_btn_1);
		tv_btn_1.setVisibility(View.GONE);
		tv_btn_2 = textView(R.id.tv_btn_2);
		tv_btn_2.setVisibility(View.GONE);
		tv_btn_3 = textView(R.id.tv_btn_3);
		tv_btn_3.setVisibility(View.GONE);
		tv_btn_4 = textView(R.id.tv_btn_4);
		tv_btn_4.setVisibility(View.GONE);
		tv_btn_5 = textView(R.id.tv_btn_5);
		tv_btn_5.setVisibility(View.GONE);
		tv_btn_6 = textView(R.id.tv_btn_6);
		tv_btn_6.setVisibility(View.GONE);
		tv_user_name = (RTextView) textView(R.id.tv_user_name);
		tv_total_amt = textView(R.id.tv_total_amt);
		tv_point_amt = textView(R.id.tv_point_amt);
		tv_coupon_amt = textView(R.id.tv_coupon_amt);
		tv_order_count = textView(R.id.tv_order_count);
		tv_order_amt = textView(R.id.tv_order_amt);
		tv_back_content = textView(R.id.tv_back_content);
		tv_order_no = textView(R.id.tv_order_no);
		tv_order_time = textView(R.id.tv_order_time);
		tv_ems_name = textView(R.id.tv_ems_name);
		tv_ems_no = textView(R.id.tv_ems_no);
		tv_ems_content = textView(R.id.tv_ems_content);
		tv_ems_time = textView(R.id.tv_ems_time);
		tv_pj_content = textView(R.id.tv_pj_content);
		tv_pj_time = textView(R.id.tv_pj_time);
		tv_pay_time = textView(R.id.tv_pay_time);
		tv_send_time = textView(R.id.tv_send_time);
		tv_received_time = textView(R.id.tv_received_time);
		tv_refund_type = textView(R.id.tv_refund_type);
		tv_refund_reason = textView(R.id.tv_refund_reason);
		imgQ1 = imageView(R.id.img_qi);
		img = imageView(R.id.img);

		ll_address = linearLayout(R.id.ll_address);
		ll_button = linearLayout(R.id.ll_button);
		ll_button2 = linearLayout(R.id.ll_button2);
		ll_back_content = linearLayout(R.id.ll_back_content);
		ll_back_content.setVisibility(View.GONE);
		ll_ems = linearLayout(R.id.ll_ems);
		ll_ems.setVisibility(View.GONE);
		ll_pj = linearLayout(R.id.ll_pj);
		ll_pj.setVisibility(View.GONE);
		ll_pay_time = linearLayout(R.id.ll_pay_time);
		ll_pay_time.setVisibility(View.GONE);
		ll_send_time = linearLayout(R.id.ll_send_time);
		ll_send_time.setVisibility(View.GONE);
		ll_received_time = linearLayout(R.id.ll_received_time);
		ll_received_time.setVisibility(View.GONE);
		ll_refund = linearLayout(R.id.ll_refund);
		ll_refund.setVisibility(View.GONE);

		id_gridview1 = findViewById(R.id.gridView);
		imageAdapter = new ImageAdapter(mContext, imgPath);
		id_gridview1.setAdapter(imageAdapter);


		listview_spec = (MyListView) findViewById(R.id.listview);
		orderListAdapter = new OrderListAdapter(mContext, orderListInfos);
		listview_spec.setAdapter(orderListAdapter);


		orderId = getIntent().getLongExtra("orderId", 0);
		if (orderId == 0){
			ToastUtils.CustomShow(mContext, "订单号为空");
			return;
		}

		type = getIntent().getStringExtra("type");



	}



	@Override
	public void onBackPressed() {
		super.onBackPressed();
		EventBus.getDefault().post(new MessageEvent(type));
	}

	private void setData() {

		int status = orderItemDetailInfo.getStatus();//getIntent().getIntExtra("status", 0);


		orderListInfos.clear();
		orderListInfos.addAll(orderItemDetailInfo.getOrderGoodItemList());
		orderListAdapter.notifyDataSetChanged();

		tv_status_name.setText(EnumConsts.OrderStatus.getByState(orderItemDetailInfo.getStatus()).getName());
		tv_recipients.setText(StringUtils.isBlank(orderItemDetailInfo.getCustomerName()) ? "" : orderItemDetailInfo.getCustomerName());
		tv_address_content.setText((StringUtils.isBlank(orderItemDetailInfo.getCity()) ? "" : orderItemDetailInfo.getCity()) + (StringUtils.isBlank(orderItemDetailInfo.getArea()) ? "" : orderItemDetailInfo.getArea()));
		tv_phone.setText(StringUtils.isBlank(orderItemDetailInfo.getPhone()) ? "" : orderItemDetailInfo.getPhone());

		tv_user_name.setText(StringUtils.isBlank(orderItemDetailInfo.getMemberName()) ? "" : orderItemDetailInfo.getMemberName());
		tv_total_amt.setText("￥"+ StringUtils.formatIntMoney(orderItemDetailInfo.getGoodAmount()));

		tv_point_amt.setText("积分抵扣金额: ￥"+StringUtils.formatIntMoney(orderItemDetailInfo.getBonusCover()));
		tv_coupon_amt.setText("优惠券抵扣金额: ￥"+StringUtils.formatIntMoney(orderItemDetailInfo.getCouponCover()));

		tv_order_count.setText("共"+orderItemDetailInfo.getGoodNum()+"件 合计（含快递："+StringUtils.formatIntMoney(orderItemDetailInfo.getFreightCharge())+"元)");
		tv_order_amt.setText("￥"+StringUtils.formatIntMoney(orderItemDetailInfo.getGoodAmount()-orderItemDetailInfo.getBonusCover()-orderItemDetailInfo.getCouponCover() + orderItemDetailInfo.getFreightCharge()));
		tv_order_no.setText(StringUtils.isBlank(orderItemDetailInfo.getOrderNo()) ? "" : orderItemDetailInfo.getOrderNo());
		tv_order_time.setText(StringUtils.isBlank(orderItemDetailInfo.getGmtCreate()) ? "" : orderItemDetailInfo.getGmtCreate());
		tv_status_time.setVisibility(View.GONE);
//		img.setVisibility(View.VISIBLE);
		ll_refund.setVisibility(View.GONE);
		if (StringUtils.isBlank(orderItemDetailInfo.getRefundImg())){
			id_gridview1.setVisibility(View.GONE);
		}else{
			id_gridview1.setVisibility(View.VISIBLE);
			String [] imgpath = StringUtils.spiltStrings(orderItemDetailInfo.getRefundImg(), ",");
			imgPath.clear();
			imgPath.addAll(Arrays.asList(imgpath));
			imageAdapter.notifyDataSetChanged();
		}
		if (EnumConsts.OrderStatus.ORDER_STATUS_YFH.getState() == status){ //已发货
//			tv_status_time.setText("剩余5天4小时36分确认收货（逾期自动收货）");
			tv_btn_6.setVisibility(View.GONE);
			ll_button.setVisibility(View.GONE);
			tv_btn_6.setText("复制订单");
			tv_btn_6.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					ClipboardManager copy = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
					copy.setText("fdsfdsfs");
					ToastUtils.CustomShow(mContext, "复制成功");
				}
			});
			if (!StringUtils.isBlank(orderItemDetailInfo.getExpressName())) {
				tv_ems_name.setText(orderItemDetailInfo.getExpressName());
			}else{
				tv_ems_name.setVisibility(View.GONE);
			}
			if (!StringUtils.isBlank(orderItemDetailInfo.getExpressNo())) {
				tv_ems_no.setText(orderItemDetailInfo.getExpressNo());
			}else {
				tv_ems_no.setVisibility(View.GONE);
			}
			if (!StringUtils.isBlank(orderItemDetailInfo.getExpressNo())) {
				if (orderItemDetailInfo.getExpressOutDTO() != null && orderItemDetailInfo.getExpressOutDTO().getData().size() > 0) {
					String str = orderItemDetailInfo.getExpressOutDTO().getData().get(0).getContext() + "\r\n" + orderItemDetailInfo.getExpressOutDTO().getData().get(0).getTime();
					tv_ems_content.setText(str);
				} else {
					tv_ems_content.setText("暂无物流详情");
				}
			}else{
				tv_ems_content.setText("商家自送");
			}
			tv_ems_time.setText("--");
			tv_ems_time.setVisibility(View.GONE);
			ll_ems.setVisibility(View.VISIBLE);
			ll_ems.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					if (orderItemDetailInfo.getExpressOutDTO() != null && orderItemDetailInfo.getExpressOutDTO().getData().size() > 0) {
						startActivity(new Intent(mContext, MyLogisticsDetailActivity.class).putExtra("logisticsDetail", orderItemDetailInfo.getExpressOutDTO()));
					}
				}
			});

			if (!StringUtils.isBlank(orderItemDetailInfo.getPayTime())) {
				ll_pay_time.setVisibility(View.VISIBLE);
				tv_pay_time.setText(orderItemDetailInfo.getPayTime());
			}else{
				ll_pay_time.setVisibility(View.GONE);
			}
			if (!StringUtils.isBlank(orderItemDetailInfo.getDeliverTime())) {
				ll_send_time.setVisibility(View.VISIBLE);
				tv_send_time.setText(orderItemDetailInfo.getDeliverTime());
			}else {
				ll_send_time.setVisibility(View.GONE);
			}
			if (StringUtils.isBlank(orderItemDetailInfo.getRemark())){
				ll_back_content.setVisibility(View.GONE);
			}else {
				ll_back_content.setVisibility(View.VISIBLE);
				tv_back_content.setText(orderItemDetailInfo.getRemark());
			}

		}else if (EnumConsts.OrderStatus.ORDER_STATUS_DFK.getState() == status) { // 待付款
//			tv_status_time.setText("");
			ll_button.setVisibility(View.GONE);
			tv_btn_3.setVisibility(View.GONE);
			tv_btn_3.setText("复制地址");
			tv_btn_3.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					ClipboardManager copy = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
					copy.setText("fdsfdsfs");
					ToastUtils.CustomShow(mContext, "复制成功");
				}
			});
			tv_btn_4.setVisibility(View.GONE);
			tv_btn_4.setText("复制订单");
			tv_btn_4.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					ClipboardManager copy = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
					copy.setText("fdsfdsfs");
					ToastUtils.CustomShow(mContext, "复制成功");
				}
			});
			tv_btn_5.setVisibility(View.VISIBLE);
			tv_btn_5.setText("取消订单");
			tv_btn_5.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					MyDialog.Builder builder = new MyDialog.Builder(mContext);
					builder.setTitle("提示");
					builder.setMessage("确定取消订单吗？");
					builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
//                        dialog.dismiss();
							doCancalOrder(orderItemDetailInfo.getId(), dialog);
						}
					});
					builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int arg1) {
							dialog.dismiss();
						}
					});
					builder.create().show();
				}
			});
			tv_btn_6.setVisibility(View.VISIBLE);
			tv_btn_6.setText("修改价格");
			tv_btn_6.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					showEditPrice(orderItemDetailInfo.getId(), orderItemDetailInfo.getGoodAmount(), orderItemDetailInfo.getFreightCharge());
				}
			});
			if (StringUtils.isBlank(orderItemDetailInfo.getRemark())){
				ll_back_content.setVisibility(View.GONE);
			}else {
				ll_back_content.setVisibility(View.VISIBLE);
				tv_back_content.setText(orderItemDetailInfo.getRemark());
			}

		}else if (EnumConsts.OrderStatus.ORDER_STATUS_DFH.getState() == status) { //待发货
//			tv_status_time.setText("--");
			tv_btn_2.setVisibility(View.VISIBLE);
			tv_btn_2.setText("商家自送");
			tv_btn_2.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					MyDialog.Builder builder = new MyDialog.Builder(mContext);
					builder.setTitle("提示");
					builder.setMessage("确定要自送吗？");
					builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
//                        dialog.dismiss();
							doMechantSend(orderItemDetailInfo.getId(), dialog);
						}
					});
					builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int arg1) {
							dialog.dismiss();
						}
					});
					builder.create().show();
				}
			});
			tv_btn_3.setVisibility(View.VISIBLE);
			tv_btn_3.setText("发货");
			tv_btn_3.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
//					showEmsNo();
					startActivity(new Intent(mContext, ActivityGetEms.class).putExtra("id", orderItemDetailInfo.getId()));
				}
			});
			tv_btn_6.setVisibility(View.GONE);
			tv_btn_6.setText("复制订单");
			tv_btn_6.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					ClipboardManager copy = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
					copy.setText("fdsfdsfs");
					ToastUtils.CustomShow(mContext, "复制成功");
				}
			});

			if (!StringUtils.isBlank(orderItemDetailInfo.getPayTime())) {
				ll_pay_time.setVisibility(View.VISIBLE);
				tv_pay_time.setText(orderItemDetailInfo.getPayTime());
			}else{
				ll_pay_time.setVisibility(View.GONE);
			}
			if (StringUtils.isBlank(orderItemDetailInfo.getRemark())){
				ll_back_content.setVisibility(View.GONE);
			}else {
				ll_back_content.setVisibility(View.VISIBLE);
				tv_back_content.setText(orderItemDetailInfo.getRemark());
			}

		}else if (EnumConsts.OrderStatus.ORDER_STATUS_DPJ.getState() == status) { //待评价
//			tv_status_time.setText("--");
			tv_btn_6.setVisibility(View.GONE);
			ll_button.setVisibility(View.GONE);
			tv_btn_6.setText("复制订单");
			tv_btn_6.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					ClipboardManager copy = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
					copy.setText("fdsfdsfs");
					ToastUtils.CustomShow(mContext, "复制成功");
				}
			});
			if (!StringUtils.isBlank(orderItemDetailInfo.getExpressName())) {
				tv_ems_name.setText(orderItemDetailInfo.getExpressName());
			}else{
				tv_ems_name.setVisibility(View.GONE);
			}
			if (!StringUtils.isBlank(orderItemDetailInfo.getExpressNo())) {
				tv_ems_no.setText(orderItemDetailInfo.getExpressNo());
			}else {
				tv_ems_no.setVisibility(View.GONE);
			}
			if (orderItemDetailInfo.getExpressOutDTO() != null && orderItemDetailInfo.getExpressOutDTO().getData().size() > 0) {
				String str = orderItemDetailInfo.getExpressOutDTO().getData().get(0).getContext() + "\r\n" + orderItemDetailInfo.getExpressOutDTO().getData().get(0).getTime();
				tv_ems_content.setText(str);
			}else{
				tv_ems_content.setText("暂无物流详情");
			}
			tv_ems_time.setText("--");
			tv_ems_time.setVisibility(View.GONE);
			ll_ems.setVisibility(View.VISIBLE);
			ll_ems.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					if (orderItemDetailInfo.getExpressOutDTO() != null && orderItemDetailInfo.getExpressOutDTO().getData().size() > 0) {
						startActivity(new Intent(mContext, MyLogisticsDetailActivity.class).putExtra("logisticsDetail", orderItemDetailInfo.getExpressOutDTO()));
					}
				}
			});

			if (!StringUtils.isBlank(orderItemDetailInfo.getPayTime())) {
				ll_pay_time.setVisibility(View.VISIBLE);
				tv_pay_time.setText(orderItemDetailInfo.getPayTime());
			}else{
				ll_pay_time.setVisibility(View.GONE);
			}
			if (!StringUtils.isBlank(orderItemDetailInfo.getDeliverTime())) {
				ll_send_time.setVisibility(View.VISIBLE);
				tv_send_time.setText(orderItemDetailInfo.getDeliverTime());
			}else {
				ll_send_time.setVisibility(View.GONE);
			}
			if (StringUtils.isBlank(orderItemDetailInfo.getRemark())){
				ll_back_content.setVisibility(View.GONE);
			}else {
				ll_back_content.setVisibility(View.VISIBLE);
				tv_back_content.setText(orderItemDetailInfo.getRemark());
			}
		}else if (EnumConsts.OrderStatus.ORDER_STATUS_TKZ.getState() == status) { //退款中
//			tv_status_time.setText("--");
			tv_btn_2.setVisibility(View.VISIBLE);
			tv_btn_2.setText("拒绝退款");
			tv_btn_2.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					DialogUtils.showBackContentDialog(mContext, "拒绝退款", "拒绝原因", "",  new DialogUtils.Callback() {
						@Override
						public void getData(String data, MyCustomDialog dialog) {
							doRefundSure(orderItemDetailInfo.getId(), "", data, dialog, 2);
						}
					});
				}
			});
			tv_btn_3.setVisibility(View.VISIBLE);
			tv_btn_3.setText("确认退款");
			tv_btn_3.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					String amt = StringUtils.formatIntMoney(orderItemDetailInfo.getGoodAmount()-orderItemDetailInfo.getBonusCover()-orderItemDetailInfo.getCouponCover() + orderItemDetailInfo.getFreightCharge());
					DialogUtils.showDialogRefund(mContext, amt, new RefundCallbackListener() {
						@Override
						public void refundCallback(String amt, String content, MyCustomDialog dialog) {
							doRefundSure(orderItemDetailInfo.getId(), StringUtils.changeY2F(amt), "", dialog, 1);
						}
					});
				}
			});
			tv_btn_6.setVisibility(View.GONE);
			tv_btn_6.setText("复制订单");
			tv_btn_6.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					ClipboardManager copy = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
					copy.setText("fdsfdsfs");
					ToastUtils.CustomShow(mContext, "复制成功");
				}
			});

			if (!StringUtils.isBlank(orderItemDetailInfo.getPayTime())) {
				ll_pay_time.setVisibility(View.VISIBLE);
				tv_pay_time.setText(orderItemDetailInfo.getPayTime());
			}else{
				ll_pay_time.setVisibility(View.GONE);
			}
			if (!StringUtils.isBlank(orderItemDetailInfo.getDeliverTime())) {
				ll_send_time.setVisibility(View.VISIBLE);
				tv_send_time.setText(orderItemDetailInfo.getDeliverTime());
			}else {
				ll_send_time.setVisibility(View.GONE);
			}
			if (StringUtils.isBlank(orderItemDetailInfo.getRemark())){
				ll_back_content.setVisibility(View.GONE);
			}else {
				ll_back_content.setVisibility(View.VISIBLE);
				tv_back_content.setText(orderItemDetailInfo.getRemark());
			}

			if (orderItemDetailInfo.getRefundType() == 1) {
				tv_refund_type.setText("退款类型: 收到货退款");
				ll_refund.setVisibility(View.VISIBLE);
			}else if (orderItemDetailInfo.getRefundType() == 2){
				tv_refund_type.setText("退款类型: 未收到货退款");
				ll_refund.setVisibility(View.VISIBLE);
			}else {
				ll_refund.setVisibility(View.GONE);
			}

			if(StringUtils.isBlank(orderItemDetailInfo.getRefundReason())) {
				tv_refund_reason.setVisibility(View.GONE);
			}else{
				tv_refund_reason.setText(orderItemDetailInfo.getRefundReason());
			}




		}else if (EnumConsts.OrderStatus.ORDER_STATUS_YWC.getState() == status || EnumConsts.OrderStatus.ORDER_STATUS_YTK.getState() == status || EnumConsts.OrderStatus.ORDER_STATUS_TKJJ.getState() == status) { //已完成
//			tv_status_time.setText("--");
			if (EnumConsts.OrderStatus.ORDER_STATUS_YWC.getState() == status) {
				if (orderItemDetailInfo.getUserRefund() == 2) {
					StringBuilder builder = new StringBuilder();
					builder.append(tv_status_name.getText().toString().trim());
					builder.append("(拒绝退款)");
					tv_status_name.setText(builder.toString());

				} else if (orderItemDetailInfo.getUserRefund() == 3) {
					StringBuilder builder = new StringBuilder();
					builder.append(tv_status_name.getText().toString().trim());
					builder.append("(退款成功)");
					tv_status_name.setText(builder.toString());
				}

			}
			if (!StringUtils.isBlank(orderItemDetailInfo.getRefuseReason())) {
				tv_status_time.setVisibility(View.VISIBLE);
				tv_status_time.setText(orderItemDetailInfo.getRefuseReason());
			}
			tv_btn_6.setVisibility(View.GONE);
			ll_button.setVisibility(View.GONE);
			ll_button2.setVisibility(View.GONE);
			tv_btn_6.setText("复制订单");
			tv_btn_6.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					ClipboardManager copy = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
					copy.setText("fdsfdsfs");
					ToastUtils.CustomShow(mContext, "复制成功");
				}
			});
			if (!StringUtils.isBlank(orderItemDetailInfo.getExpressName())) {
				tv_ems_name.setText(orderItemDetailInfo.getExpressName());
			}else{
				tv_ems_name.setVisibility(View.GONE);
			}
			if (!StringUtils.isBlank(orderItemDetailInfo.getExpressNo())) {
				tv_ems_no.setText(orderItemDetailInfo.getExpressNo());
			}else {
				tv_ems_no.setVisibility(View.GONE);
			}
			if (orderItemDetailInfo.getExpressOutDTO() != null && orderItemDetailInfo.getExpressOutDTO().getData().size() > 0) {
				String str = orderItemDetailInfo.getExpressOutDTO().getData().get(0).getContext() + "\r\n" + orderItemDetailInfo.getExpressOutDTO().getData().get(0).getTime();
				tv_ems_content.setText(str);
			}else{
				tv_ems_content.setText("暂无物流详情");
			}
			tv_ems_time.setText("--");
			tv_ems_time.setVisibility(View.GONE);
			ll_ems.setVisibility(View.VISIBLE);
			ll_ems.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					startActivity(new Intent(mContext, MyLogisticsDetailActivity.class).putExtra("logisticsDetail", orderItemDetailInfo.getExpressOutDTO()));
				}
			});
			tv_pj_content.setText("订单详情");
			tv_pj_time.setVisibility(View.GONE);
			tv_pj_time.setText("评价时间："+"2017-12-15  12:02");
			ll_pj.setVisibility(View.GONE);
			ll_pj.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					startActivity(new Intent(mContext, MyCommentActivity.class));
				}
			});

			if (!StringUtils.isBlank(orderItemDetailInfo.getPayTime())) {
				ll_pay_time.setVisibility(View.VISIBLE);
				tv_pay_time.setText(orderItemDetailInfo.getPayTime());
			}else{
				ll_pay_time.setVisibility(View.GONE);
			}
			if (!StringUtils.isBlank(orderItemDetailInfo.getDeliverTime())) {
				ll_send_time.setVisibility(View.VISIBLE);
				tv_send_time.setText(orderItemDetailInfo.getDeliverTime());
			}else {
				ll_send_time.setVisibility(View.GONE);
			}
			if (StringUtils.isBlank(orderItemDetailInfo.getRemark())){
				ll_back_content.setVisibility(View.GONE);
			}else {
				ll_back_content.setVisibility(View.VISIBLE);
				tv_back_content.setText(orderItemDetailInfo.getRemark());
			}

			if (orderItemDetailInfo.getRefundType() == 1) {
				tv_refund_type.setText("退款类型: 收到货退款");
				ll_refund.setVisibility(View.VISIBLE);
			}else if (orderItemDetailInfo.getRefundType() == 2){
				tv_refund_type.setText("退款类型: 未收到货退款");
				ll_refund.setVisibility(View.VISIBLE);
			}else {
				ll_refund.setVisibility(View.GONE);
			}

			if(StringUtils.isBlank(orderItemDetailInfo.getRefundReason())) {
				tv_refund_reason.setVisibility(View.GONE);
			}else{
				tv_refund_reason.setText(orderItemDetailInfo.getRefundReason()+"\r\n"+"退款金额："+StringUtils.formatIntMoney(orderItemDetailInfo.getRefundAmount())+"元");
			}
		}else if (EnumConsts.OrderStatus.ORDER_STATUS_YGB.getState() == status ||
				EnumConsts.OrderStatus.ORDER_STATUS_YQX.getState() == status) { //已关闭
//			tv_status_time.setText("--");
			tv_btn_6.setVisibility(View.GONE);
			ll_button.setVisibility(View.GONE);
			ll_button2.setVisibility(View.GONE);
			tv_btn_6.setText("复制订单");
			tv_btn_6.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					ClipboardManager copy = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
					copy.setText("fdsfdsfs");
					ToastUtils.CustomShow(mContext, "复制成功");
				}
			});
			tv_pj_content.setText("有退款");
			tv_pj_time.setText("退款时间："+"2017-12-15  12:02");
			ll_pj.setVisibility(View.GONE);
			ll_pj.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {

				}
			});
			if (!StringUtils.isBlank(orderItemDetailInfo.getPayTime())) {
				ll_pay_time.setVisibility(View.VISIBLE);
				tv_pay_time.setText(orderItemDetailInfo.getPayTime());
			}else {
				ll_pay_time.setVisibility(View.GONE);
			}
			if (StringUtils.isBlank(orderItemDetailInfo.getRemark())){
				ll_back_content.setVisibility(View.GONE);
			}else {
				ll_back_content.setVisibility(View.VISIBLE);
				tv_back_content.setText(orderItemDetailInfo.getRemark());
			}
		}



		//判断是否备注过
		if (StringUtils.isBlank(orderItemDetailInfo.getRemark())){
			ll_back_content.setVisibility(View.GONE);
			imgQ1.setVisibility(View.VISIBLE);
			imgQ1.setImageResource(R.mipmap.icon_qi1);
			imgQ1.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					DialogUtils.showBackContentDialog(mContext, "添加备注", "备注内容", "",new DialogUtils.Callback() {
						@Override
						public void getData(String data, MyCustomDialog dialog) {
							setAddBack(orderItemDetailInfo.getId(), data, imgQ1, dialog);
						}
					});
				}
			});
		}else{
			ll_back_content.setVisibility(View.VISIBLE);
			imgQ1.setVisibility(View.INVISIBLE);
		}

	}

	private void doMechantSend(long id, final DialogInterface dialog) {


		showProgress("加载中...");
		String url = Config.SBS_CLOSE_ORDER;
		RequestParams params = new RequestParams();
		params.put("id", id);
		params.put("status", 6);

		HttpUtil.get(url, params, new HttpUtil.RequestListener() {

			@SuppressWarnings("unchecked")
			@Override
			public void success(String response) {
				disShowProgress();
				try {


					JSONObject result = new JSONObject(response);
					if (!result.optBoolean("status")) {
						showErrorMsg(result.getString("message"));
						return;
					}

					dialog.dismiss();
					loadData();

				} catch (Exception e) {
					e.getMessage();

				}
			}

			@Override
			public void failed(Throwable error) {
				disShowProgress();
				showE404();
			}
		});

	}



	private void doCancalOrder(long id, final DialogInterface dialog) {


		showProgress("加载中...");
		String url = Config.SBS_CLOSE_ORDER;
		RequestParams params = new RequestParams();
		params.put("id", id);
		params.put("status", 8);

		HttpUtil.get(url, params, new HttpUtil.RequestListener() {

			@SuppressWarnings("unchecked")
			@Override
			public void success(String response) {
				disShowProgress();
				try {


					JSONObject result = new JSONObject(response);
					if (!result.optBoolean("status")) {
						showErrorMsg(result.getString("message"));
						return;
					}

					dialog.dismiss();
					loadData();

				} catch (Exception e) {
					e.getMessage();

				}
			}

			@Override
			public void failed(Throwable error) {
				disShowProgress();
				showE404();
			}
		});

	}

	private void doRefundSure(long id, String amt, String reason, final DialogInterface dialog, int type) {


		showProgress("加载中...");
		String url = Config.SBS_REFUND_ORDER;
		RequestParams params = new RequestParams();
		params.put("id", id);
		if (type == 1) {
			params.put("status", 9);
			params.put("userRefund", 3);
			params.put("refundAmount", amt);
			params.put("refuseReason", reason);
		}else if (type == 2){
			params.put("status", 5);
			params.put("userRefund", 2);
			params.put("refuseReason", reason);
		}


		HttpUtil.get(url, params, new HttpUtil.RequestListener() {

			@SuppressWarnings("unchecked")
			@Override
			public void success(String response) {
				disShowProgress();
				try {


					JSONObject result = new JSONObject(response);
					if (!result.optBoolean("status")) {
						showErrorMsg(result.getString("message"));
						return;
					}

					dialog.dismiss();
					loadData();

				} catch (Exception e) {
					e.getMessage();

				}
			}

			@Override
			public void failed(Throwable error) {
				disShowProgress();
				showE404();
			}
		});

	}



	private void setAddBack(long id, String data, final ImageView img_qi, final MyCustomDialog dialog){
		showProgress("加载中...");

		String url = Config.SBS_ADD_REMAKE;
		RequestParams params = new RequestParams();
		params.put("id", id);
		params.put("remark", data);

		HttpUtil.get(url, params, new HttpUtil.RequestListener() {

			@SuppressWarnings("unchecked")
			@Override
			public void success(String response) {
				disShowProgress();
				try {


					JSONObject result = new JSONObject(response);
					if (!result.optBoolean("status")) {
						showErrorMsg(result.getString("message"));
						return;
					}

					//保存备注，成功更改旗子
                    img_qi.setImageResource(R.mipmap.icon_qi2);
//                    adapter.notifyDataSetChanged();
					dialog.dismiss();
					loadData();
				} catch (Exception e) {
					e.getMessage();

				}
			}

			@Override
			public void failed(Throwable error) {
				disShowProgress();
				showE404();
			}
		});
	}



	private void showEditPrice(final Long id, final Integer goodAmount, Integer freightCharge) {
		DialogUtils.showEditPriceDialog(mContext, goodAmount, freightCharge, new EditPriceCallbackListener() {
			@Override
			public void getData(String goodAmt, String emsAmt, String realAmt, MyCustomDialog dialog) {
				loadEditPrice(id, goodAmt, emsAmt, dialog);
			}
		});
	}

	private void loadEditPrice(Long id, String goodAmount, String emsAmt, final MyCustomDialog dialog) {
		showProgress("加载中...");
		String url = Config.SBS_CLOSE_ORDER;
		RequestParams params = new RequestParams();
		params.put("id", id);
		params.put("goodAmount", StringUtils.changeY2F(goodAmount));
		params.put("freightCharge", StringUtils.changeY2F(emsAmt));

		HttpUtil.get(url, params, new HttpUtil.RequestListener() {

			@SuppressWarnings("unchecked")
			@Override
			public void success(String response) {
				disShowProgress();
				try {


					JSONObject result = new JSONObject(response);
					if (!result.optBoolean("status")) {
						showErrorMsg(result.getString("message"));
						return;
					}

					dialog.dismiss();
					loadData();
				} catch (Exception e) {
					e.getMessage();

				}
			}

			@Override
			public void failed(Throwable error) {
				disShowProgress();
				showE404();
			}
		});
	}


	private void showEmsNo() {
		DialogUtils.showSendGoodsDialog(mContext, new EmsCallbackListener(){

			@Override
			public void getData(String emsNo, String emsName, MyCustomDialog dialog) {

			}

			@Override
			public void getScanData(EditText et_ems_no) {
				emsNo = et_ems_no;
				startActivityForResult(new Intent(mContext, CaptureActivity.class), 1);
			}

			@Override
			public void getEmsShortname(String trim) {

			}
		});

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		if (resultCode != RESULT_OK) {
			return;
		}
		switch (requestCode) {
			case 1:
				// 处理扫描结果（在界面上显示）
				String str = data.getStringExtra(CodeUtils.RESULT_STRING);
				emsNo.setText(str);
				break;

			default:
				break;
		}
		super.onActivityResult(requestCode, resultCode, data);
	}


	@Override
	protected void onResume() {
		super.onResume();
		loadData();
	}

	private void loadData() {

		showProgress("加载中...");

		String url = Config.SBS_MALL_ORDER_DETAIL;
		RequestParams params = new RequestParams();
		params.put("id", orderId);

		HttpUtil.get(url, params, new HttpUtil.RequestListener() {

			@SuppressWarnings("unchecked")
			@Override
			public void success(String response) {
				disShowProgress();
				try {


					JSONObject result = new JSONObject(response);
					if (!result.optBoolean("status")) {
						showErrorMsg(result.getString("message"));
						return;
					}
//					JSONObject obj = result.getJSONObject("data");
//					String mallGoodOutDTOList = obj.optString("mallGoodOutDTOList");
//					if (!StringUtils.isBlank(mallGoodOutDTOList)) {

						Gson gson = new Gson();
						// json数据转换成List
						orderItemDetailInfo = gson.fromJson(result.optString("data"), new TypeToken<OrderManagerInfo>() {
						}.getType());

						if (orderItemDetailInfo != null) {
							setData();
						}
//					}

				} catch (Exception e) {
					e.getMessage();

				}
			}

			@Override
			public void failed(Throwable error) {
				disShowProgress();
				showE404();
			}
		});
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.titleback_btn_back:
				EventBus.getDefault().post(new MessageEvent(type));
				finish();
				break;

			default:break;
		}

	}
	
}
